#include "ccamera.h"
#include "cmatrix.h"

CCamera::CCamera()
{
	this->position	= CPoint3f (0.0f,0.0f,0.0f);
	this->direction	= CVecteur3f (0.0f, 0.0f, 1.0f);
	this->up		= CVecteur3f (0.0f, 1.0f, 0.0f);
	this->side		= CVecteur3f (1.0f, 0.0f, 0.0f);
	this->_target	= this->position +  this->direction;
	this->_phi = 0.0;
	this->_theta = 0.0;
	this->_window_height = 0;
	this->_window_width = 0;
}


void CCamera::VectorsFromAngles()
{
	CMatrix Xrot(1.0, 0.0, 0.0, 0.0, cos(_theta), -sin(_theta), 0.0, sin(_theta), cos(_theta));
	CMatrix	Yrot(cos(_phi), 0.0, sin(_phi), 0.0, 1.0, 0.0, -sin(_phi), 0.0, cos(_phi));
	this->_phi = 0.0;
	this->_theta = 0.0;
	CMatrix transformMat(Yrot*Xrot);

	this->direction = transformMat * this->direction;
	this->up		= transformMat * this->up;;
	this->side		= transformMat * this->side;


	this->_target = this->position +  this->direction;
}

void CCamera::look()
{
	gluLookAt(this->position.GetX(),this->position.GetY(),this->position.GetZ(),
			  this->_target.GetX(), this->_target.GetY(), this->_target.GetZ(),
			  this->up.x,this->up.y,this->up.z);
}
